package org.speed.jdk;

import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

public class LambdaTest {


    public static void main(String[] args) {

        List<User> users = Arrays.asList(new User[]{
                new User(1L, "yyb", 12, 2110.11),
                new User(1L, "erf", 13, 110.11),
                new User(3L, "tgb", 6, 410.11),
                new User(4L, "erc", 8, 1116.11),
                new User(5L, "tyg", 32, 6540.11),
        });


        //users.forEach(user -> System.out.println(user));

        List<Long> idList = users.stream().filter(user -> user.getAge() > 10).map(user -> user.id).collect(Collectors.toList());
        boolean isMatched = idList.stream().anyMatch(p -> p == 1 );
        Set<Long> idSetList = idList.stream().collect(Collectors.toSet());
        System.out.println(idSetList);
    }


    static class User {

        private Long id;
        private String name;
        private int age;
        private double price;

        public User() {
        }

        public User(Long id, String name, int age, double price) {
            this.id = id;
            this.name = name;
            this.age = age;
            this.price = price;
        }

        public Long getId() {
            return id;
        }

        public void setId(Long id) {
            this.id = id;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public int getAge() {
            return age;
        }

        public void setAge(int age) {
            this.age = age;
        }

        public double getPrice() {
            return price;
        }

        public void setPrice(double price) {
            this.price = price;
        }

        @Override
        public String toString() {
            return "User{" +
                    "id=" + id +
                    ", name='" + name + '\'' +
                    ", age=" + age +
                    ", price=" + price +
                    '}';
        }
    }
}
